home *** CD-ROM | disk | FTP | other *** search
/ Gekkan Dennou Club 147 / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin / fdimg / oh!.2hd / OH!DEN_B.LZH / TOOLS / DC_VIEW / DCTXT.C < prev    next >
Text File  |  1995-03-20  |  10KB  |  408 lines

  1. /******************************************************************************
  2.  *    DCtxt.c:    テキスト表示処理
  3.  ******************************************************************************
  4.  *
  5.  *
  6.  */
  7. #include <stdio.h>
  8. #include <ctype.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <stat.h>
  12. #include <io.h>
  13. #include <jfctype.h>
  14. #include <doslib.h>
  15. #include <event.h>        /* イベントマンを利用するときに必要    */
  16. #include <sxgraph.h>        /* グラフ系マネージャを利用するときに必要 */
  17. #include <window.h>        /* ウィンドウマンを利用するときに必要    */
  18. #include <dialog.h>        /* ダイアログマンを利用するときに必要    */
  19. #include <task.h>        /* タスクマンを利用するときに必要    */
  20. #include "DC.h"            /* このプログラム固有のヘッダファイル    */
  21.  
  22. /******************************************************************************
  23.  *    drawtxt():    テキストの描画
  24.  ******************************************************************************
  25.  *    引数:    ComVal *pcv    共通変数へのポインタ
  26.  *        int    part    0:部分書きかえ
  27.  *                1:全画面書きかえ    
  28.  */
  29. void drawtxt(ComVal *pcv, int part)
  30. {
  31.     int i,j,jj,k,tb,vw,drawPt,end,esc;
  32.     char buff[100];
  33.     char buff2[100];
  34.     char dmyfname[100];
  35.     char *txtPt;
  36.     int *txtNo;
  37.     int pat1,pat2;
  38.     int line_no;
  39.     int cut_no;
  40.     int cut_lno,ylen;
  41.     Rect cut_rc_src;
  42.     Rect cut_rc_dst;
  43.     LPoint ppos;
  44.     Region **curRgn;
  45.     Rect rc = { 0, 0, 588, 360};
  46.     Rect rcl = {520, 363, 554, 379};
  47.  
  48.     if (pcv->loadFlag == 0)
  49.         return;
  50.  
  51.     GMSetGraph(&pcv->windowPtr->graph);
  52.     GMSetClip(pcv->txtRgnHdl);
  53.  
  54.     MMHdlLock(pcv->txt);    /* テキストのハンドルをロック    */
  55.     MMHdlLock(pcv->txtNo);
  56.  
  57.     txtPt = *(pcv->txt);
  58.     txtNo = *(pcv->txtNo);
  59.  
  60.     if (part != 0) {
  61.         if (pcv->scrollDir > 0) {    /* テキストスクロール    */
  62.             GMScroll(&rc, LONGWORD(0,-12 * pcv->scrollstep), pcv->updateRgnHdl);
  63.             end = pcv->scrollstep + 1;
  64.             drawPt = (29 - pcv->scrollstep) * 12;
  65.             line_no = pcv->ofset + 29 - pcv->scrollstep;
  66.             txtPt = txtPt + *(txtNo + line_no);
  67.         } else {            /* テキスト逆スクロール    */
  68.             GMScroll(&rc, LONGWORD(0, 12 * pcv->scrollstep), pcv->updateRgnHdl);
  69.             end = pcv->scrollstep + 1;
  70.             drawPt = 0;
  71.             line_no = pcv->ofset;
  72.             txtPt = txtPt + *(txtNo + pcv->ofset);
  73.         }
  74.     } else {                /* 全テキスト表示    */
  75.         GMForeColor(G_BLACK);
  76.         GMFillRect(&rc);
  77.         GMForeColor(G_WHITE);
  78.         end = 30;
  79.         drawPt = 0;
  80.         line_no = pcv->ofset;
  81.         txtPt = txtPt + *(txtNo + pcv->ofset);
  82.     }
  83.  
  84.     for(i=0;i<end;i++) {            /* テキスト描画        */
  85.         if (pcv->Maxline < (line_no + i)) break;
  86.         j = 0;
  87.         jj = 0;
  88.         vw = 0;
  89.         pcv->pre_esc = 33;
  90.         GMMove(LONGWORD(6,drawPt + i*12));
  91.         while(1) {
  92.             if (*txtPt == 13) {            /* 改行処理    */
  93.                 buff[j] = 0;
  94.                 txtPt++;
  95.                 break;
  96.             }
  97.  
  98.             if (*txtPt == 10) {            /* LF処理    */
  99.                 txtPt++;
  100.                 continue;
  101.             }
  102.  
  103.             if (*txtPt == 9) {            /* TAB処理    */
  104.                 if (vw == 1) {
  105.                     jj = jj + j / 2;
  106.                     GMMove(LONGWORD(jj * 6 + 6,drawPt + i * 12));
  107.                 }
  108.                 tb = 8 - (jj % 8);
  109.                 buff[j] = 0;
  110.                 if (j > 0)
  111.                     GMDrawStrZ(buff);
  112.                 GMMoveRel(LONGWORD(tb * 6,0));
  113.                 j = 0;
  114.                 jj = jj + tb;
  115.                 txtPt++;
  116.                 continue;
  117.             }
  118.  
  119.  
  120.             if (jj == 94){                /* 行の折り返し    */
  121.                 pat1 =((int)*txtPt << 8) + (int)*(txtPt+1);
  122.                 if (jiszen(pat1) && (*(txtPt + 2)  == 13)) {
  123.                     buff[j++] = *txtPt;
  124.                     txtPt++;
  125.                     buff[j++] = *txtPt;
  126.                     txtPt++;
  127.                     txtPt++;
  128.                     buff[j] = 0;
  129.                     break;
  130.                 }
  131.                 pat2 =((int)*(txtPt-1) << 8) + (int)*txtPt;
  132.                 if (jiszen(pat2) && (!jiszen(pat1))) {
  133.                     buff[j] = *txtPt;
  134.                     buff[j+1] = 0;
  135.                     txtPt++;
  136.                     if (*(txtPt+1) == 13) txtPt++;
  137.                     break;
  138.                 }
  139.             }
  140.  
  141.             if (*txtPt ==  '%') {            /* %コード処理    */
  142.                 if (*(txtPt + 1) == 'V') {    /* 倍角設定    */
  143.                     vw = 1;
  144.                     txtPt = txtPt + 4;
  145.                     buff[j] = 0;
  146.                     GMDrawStrZ(buff);
  147.                     j = 0;
  148.                     continue;
  149.                 }
  150.                 if ((*(txtPt + 1) == 'C') && (*(txtPt+2) != 'U')) { /* カットファイル  */
  151.                     cut_no = *(txtPt+2) - '0';
  152.                     cut_lno = *(txtPt+3) - '0';
  153.                     if (*(txtPt+4)==':') {
  154.                         while(*txtPt++ != '.') {
  155.                         }
  156.                         txtPt = txtPt + 3;
  157.                     } else {
  158.                         txtPt = txtPt + 4;
  159.                     }
  160.                     if (j>0) {
  161.                         buff[j] = 0;
  162.                         GMDrawStrZ(buff);
  163.                         j = 0;
  164.                     }
  165.  
  166.                     GMLockBits(pcv->bitsH[cut_no]);
  167.                     pcv->offgraph[cut_no].bmap = &(*pcv->bitsH[cut_no])->bmap;
  168.  
  169.                     cut_rc_src.d.top = cut_lno * 12;
  170.                     cut_rc_src.d.right = pcv->offgraph[cut_no].rect.d.right;
  171.                     if (cut_rc_src.d.top + 12 > pcv->offgraph[cut_no].rect.d.bottom) {
  172.                         cut_rc_src.d.bottom = pcv->offgraph[cut_no].rect.d.bottom;
  173.                         ylen = cut_rc_src.d.bottom - cut_rc_src.d.top;
  174.                     } else {    
  175.                         cut_rc_src.d.bottom = cut_rc_src.d.top + 12;
  176.                         ylen = 12;
  177.                     }    
  178.                     cut_rc_src.d.left = 0;
  179.  
  180.                     ppos = GMGetLoc();
  181.                     cut_rc_dst.d.top = LOWWORD(ppos);
  182.                     cut_rc_dst.d.right = HIWORD(ppos) + cut_rc_src.d.right;
  183.                     cut_rc_dst.d.bottom = cut_rc_dst.d.top + ylen;
  184.                     cut_rc_dst.d.left = HIWORD(ppos);
  185.  
  186.                     GMCopy(&(*pcv->bitsH[cut_no])->bmap, pcv->windowPtr->graph.bmap,
  187.                         &cut_rc_src, &cut_rc_dst,
  188.                             G_PSET, NULL);  /* pcv->windowPtr->update); */
  189.                     GMUnlockBits(pcv->bitsH[cut_no]);
  190.                     GMMoveRel(LONGWORD(cut_rc_src.d.right,0));
  191.                     continue;
  192.                 }
  193.             }
  194.  
  195.             if (*txtPt ==  24) {            /* 倍角解除    */
  196.                 if (vw == 1) {
  197.                     esc_mode(pcv, 0);
  198.                     buff[j] = 0;
  199.                     GMFontKind(G_ROM16);
  200.                     GMFontSize(LONGWORD(16,16));
  201.                     GMMoveRel(LONGWORD(0,4));
  202.                     GMDrawStrZ(buff);
  203.                     GMFontKind(G_ROM12);
  204.                     GMFontSize(LONGWORD(12,12));
  205.                     GMMoveRel(LONGWORD(0,-4));
  206.                     vw = 0;
  207.                     jj = jj + j / 2;
  208.                     GMMove(LONGWORD(jj * 6 + 6,drawPt + i * 12));
  209.                     j = 0;
  210.                     txtPt++;
  211.                     continue;
  212.                 }
  213.                 txtPt++;
  214.                 continue;
  215.             }
  216.  
  217.             if (*txtPt ==  27) {            /* esc文字属性    */
  218.                 if (*(txtPt+1) == '[') {
  219.                     buff2[0] = 0;
  220.                     esc = 0;
  221.                     txtPt++;
  222.                     txtPt++;
  223.                     while(*txtPt != 'm' && *txtPt != 'C') {
  224.                         buff2[esc++] = *(txtPt++);
  225.                     }
  226.                     if (esc != 0) {
  227.                         if (*txtPt == 'C') {
  228.                             buff2[esc] = 0;
  229.                             esc = atoi(buff2);
  230.                             GMMoveRel(LONGWORD(esc*6, 0));
  231.                             txtPt++;
  232.                             j = 0;
  233.                             continue;
  234.                         }
  235.                         buff2[esc] = 0;
  236.                         esc = atoi(buff2);
  237.                         buff[j] = 0;
  238.                         GMDrawStrZ(buff);
  239.  
  240.                         esc_mode(pcv, esc);
  241.  
  242.                         txtPt++;
  243.                         j = 0;
  244.                         continue;
  245.                     } else {
  246.                         buff[j] = 0;
  247.                         GMDrawStrZ(buff);
  248.  
  249.                         esc_mode(pcv, 0);
  250.  
  251.                         txtPt++;
  252.                         j = 0;
  253.                         continue;
  254.                     }
  255.                 }
  256.             }
  257.  
  258.             if (jj>=94) {
  259.                 break;
  260.             }
  261.        
  262.             buff[j++] = *(txtPt++);
  263.             buff[j] = 0;
  264.  
  265.             jj++;
  266.         }
  267.  
  268.         if (vw) {
  269.             GMFontKind(G_ROM16);
  270.             GMFontSize(LONGWORD(16,16));
  271.             GMMoveRel(LONGWORD(0,4));
  272.             }
  273.         GMDrawStrZ(buff);
  274.         if (vw) {
  275.             GMFontKind(G_ROM12);
  276.             GMFontSize(LONGWORD(12,12));
  277.             GMMoveRel(LONGWORD(0,-4));
  278.             vw = 0;
  279.         }
  280.         pcv->pre_esc = 33;
  281.         esc_mode(pcv, 33);
  282.     }
  283.     MMHdlUnlock(pcv->txtNo);    /* テキストのハンドルをアンロック */
  284.     MMHdlUnlock(pcv->txt);
  285.     GMSetClip(pcv->winRgnHdl);
  286.     CMValueSet(pcv->volHdl, pcv->ofset);
  287.     if (!pcv->lineDisp) {        /* 行番号表示            */
  288.         GMShadowRect(&rcl);
  289.         GMMove(LONGWORD(521,364));
  290.         sprintf(buff, "%5d", pcv->ofset + 1);
  291.         GMDrawStrZ(buff);
  292.     }
  293. }
  294.  
  295. /******************************************************************************
  296.  *    esc_mode():    テキストの描画モード変更処理
  297.  ******************************************************************************
  298.  *    引数:    ComVal *pcv    共通変数へのポインタ
  299.  *        int    esc    描画モード
  300.  */
  301. int esc_mode(ComVal *pcv, int esc)
  302. {
  303.     int esc_color, pre_esc_color;
  304.     int esc_mode, pre_esc_mode;
  305.  
  306.     GMSetGraph(&pcv->windowPtr->graph);
  307.     if (esc == 0) 
  308.         esc = 33;
  309.  
  310.     pre_esc_color = (pcv->pre_esc % 10) % 4;
  311.     pre_esc_mode = pcv->pre_esc;
  312.     esc_color = (esc % 10) % 4;
  313.     esc_mode = esc;
  314.  
  315.     if (esc == 1) {
  316.         if (pre_esc_mode < 34)
  317.             esc_mode = pre_esc_mode + 4;
  318.         if (pre_esc_mode > 43)
  319.             esc_mode = pre_esc_mode - 4;
  320.         esc_color = pre_esc_color;
  321.     }
  322.     if (esc == 7) {
  323.         if (pre_esc_mode < 38)
  324.             esc_mode = pre_esc_mode + 10;
  325.         if (pre_esc_mode > 39)
  326.             esc_mode = pre_esc_mode - 10;
  327.         esc_color = pre_esc_color;
  328.     }
  329.  
  330.     switch(esc_color) {
  331.         case 0:    GMForeColor(G_BLACK);
  332.             break;
  333.         case 1:    GMForeColor(G_BLUE);
  334.             break;
  335.         case 2:    GMForeColor(G_RED);
  336.             break;
  337.         case 3:    GMForeColor(G_WHITE);
  338.             break;
  339.     }
  340.  
  341.     if (esc_mode < 34) {
  342.         GMFontMode(G_PSET);
  343.         GMFontFace(G_PLANE);
  344.         GMFontSize(LONGWORD(12,12));
  345.     return (esc);
  346.     }
  347.     if (esc_mode < 38) {
  348.         GMFontMode(G_PSET);
  349.         GMFontFace(G_BOLD);
  350.         GMFontSize(LONGWORD(11,12));
  351.     return (esc);
  352.     }
  353.     if (esc_mode < 44) {
  354.         GMFontMode(G_NXOR);
  355.         GMFontFace(G_PLANE);
  356.         GMFontSize(LONGWORD(12,12));
  357.     return (esc);
  358.     }
  359.     if (esc_mode < 34) {
  360.         GMFontMode(G_NXOR);
  361.         GMFontFace(G_BOLD);
  362.         GMFontSize(LONGWORD(11,12));
  363.     return (esc);
  364.     }
  365.  
  366.     return(esc);
  367. }
  368.  
  369. /******************************************************************************
  370.  *    scrollTxt():    テキストのスクロール処理
  371.  ******************************************************************************
  372.  *    引数:    ComVal *pcv    共通変数へのポインタ
  373.  *        int    part     1:上スクロール
  374.  *                -1:下スクロール    
  375.  */
  376. int scrollTxt(ComVal *pcv, int dir)
  377. {
  378.     int sclbuff;
  379.     pcv->scrollDir = dir;
  380.  
  381.     if (pcv->loadFlag == 0)
  382.         return;
  383.  
  384.     if (dir > 0) {
  385.         if (pcv->ofset < (pcv->Maxline - 29)) {
  386.             pcv->ofset = pcv->ofset + pcv->scrollstep;
  387.             drawtxt(pcv, 1); /* ウィンドウ内部を描画する    */
  388.             return (1);
  389.         }
  390.     } else {
  391.         if (pcv->ofset > 0) {
  392.             pcv->ofset = pcv->ofset - pcv->scrollstep;
  393.             if ((pcv->ofset - pcv->scrollstep) < 0) {
  394.                 sclbuff = pcv->scrollstep;
  395.                 pcv->scrollstep = pcv->scrollstep + pcv->ofset;
  396.                 pcv->ofset = 0;
  397.                 drawtxt(pcv, 1); /* ウィンドウ内部を描画する    */
  398.                 pcv->scrollstep = sclbuff;
  399.             } else {
  400.                 drawtxt(pcv, 1); /* ウィンドウ内部を描画する    */
  401.             }
  402.             return (1);
  403.         }
  404.     }
  405.     return (0);
  406. }
  407. STR@&xEdEV3.00<@(!%G0JHH     
  408. S((SBxヨH vケ > >Ohh$000ヨ=4